<?php
namespace news\Controller;
use Common\Model\NewsCommentModel;
use News\Controller\CommonController;
use Common\Model\NewsModel;


class NewsController extends CommonController {
    public function index(){
        $id = I('id',0,'int');
        if($id) {
            $model = new NewsModel;
            $data = $model->find($id);
            if ($data) {
                //获取父级栏目id
                $cateogry = $this->getFatherCategory($data['cid']);
                //相关栏目

                $HotCategory = $this->getInfoCategory($data['cid'],$cateogry['father']['id']);

                $idArr = array_column($HotCategory,'id');
                $hotInfo = $this->getInfoInId($idArr);

                $commentModel = new NewsCommentModel();
                $comment = $commentModel->getComByInfoId($id);

                $data['content'] = htmlspecialchars_decode($data['content']);

                $this->assign('data', $data)
                    ->assign("hotInfo",$hotInfo)
                    ->assign('comment',$comment)
                    ->assign('hotCategory',$HotCategory)
                    ->assign("fatherCateogry",$cateogry['father'])
                    ->assign('currentCategory',$cateogry['current']);
                $this->display('/news/news');
                exit();
            }
        }
        $this->display(':404');
    }
}